Grokking Scalable Systems for Interviews
Rate this course
Ask Author
Contribute
Back to course home

4% completed

Vote For New Content
Introduction
Course Overview
Who This Course Is for
Caching
What Is Negative Caching and When Should You Cache 404 or Empty Results?
What Is the Difference Between Soft TTL and Hard TTL, and Why Does It Matter?
How Can a Bloom Filter Reduce Cache or Database Load?
What Is Distributed Locking for Cache Rebuilds, and How Does It Prevent Cache Stampedes?
Load Balancing
What Are Sticky Sessions (Session Affinity) and When Should I Avoid Them?
What Is the Difference between Liveness Checks and Readiness Checks in Load Balancers?
What is Global Server Load Balancing (GSLB) and How GeoDNS and Anycast Work?
API Basics
What are the Main API Pagination Strategies (offset, cursor, keyset), and When Should I Use Each?
What are HTTP Conditional Requests (ETag, If‑None‑Match, Last‑Modified) and How They Reduce Load?
What Is the Difference between Rate Limiting and Throttling and Quotas?
What Are Idempotency Keys and How to Implement Them Safely for Payments
Databases
What are SQL Isolation Levels (Read Committed, Repeatable Read, Serializable), and What Anomalies Do They Prevent?
What Is a Write‑Ahead Log (WAL), and How Does It Ensure Durability?
What Is the Difference Between Synchronous and Asynchronous Replication, and When Should I Use Read Replicas?
What Is MVCC (Multi‑Version Concurrency Control), and How Does It Enable Concurrent Reads and Writes?
What Are Safe Patterns for Online Schema Changes vs. Offline Migrations?
Scalability
What is Little’s Law and How to Use It for Quick Capacity Estimates in System Design
How Can I do Back-of-the-Envelope Sizing for QPS, Bandwidth, Storage, and Peak vs. Average Load?
What are Cold Starts and Warm Starts, and Why Do They Matter for Performance?
Sharding and Partitioning
How Do I Choose a Good Shard Key and Avoid Hotspots (Bucketing and Key Randomization)?
What Are Range Sharding, Directory‑Based Sharding, and Geo‑Sharding, and What Are the Common Use Cases?
What Is the Difference Between Rendezvous Hashing and Consistent Hashing, and When Should I Use Each?
Messaging and Streaming
What Do At‑most‑once, At‑least‑once, And Exactly‑once Delivery Semantics Mean?
What Are Idempotent Producers And Consumers, And How Do De‑duplication Keys Work?
What Is Message Ordering, How Do Partition Keys Affect It, And When Can Ordering Break?
What Are Windowing And Watermarking In Streaming Systems, In Simple Terms?
Consistency and Replication
What Is Quorum (N, R, W), And Why Does R + W > N Give Strongly Consistent Reads?
What Are Common Conflict Resolution Strategies (Last‑write‑wins, Vector Clocks, Logical Clocks)?
What Are Read Repair, Hinted Handoff, And Anti‑entropy (Merkle Trees) In Eventually Consistent Systems?
Observability
What Is The Difference Between SLI, SLO, And SLA, And Can You Give Simple Examples?
What Is Opentelemetry, And How Do Traces, Spans, Metrics, And Logs Fit Together?
What Is An Error Budget, And How Should It Guide Release Decisions?
Security
What Are The Trade‑offs Between Server‑stored Sessions And JWTs for Authentication?
What Is The Difference Between TLS And MTLS, And When Is MTLS Appropriate For Service‑to‑service Auth?
What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare?
What Is A Replay Attack, And How Is It Different from Idempotency Issues?
Networking
What Are The Differences Between TCP, UDP, And QUIC, And When Should I Use Each?
What Is The Difference Between A Forward Proxy, A Reverse Proxy, And NAT?
What Changed From HTTP/1.1 To HTTP/2 To HTTP/3, And What Are Head‑of‑line Blocking And Multiplexing?
Storage
What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing?
What Are Checksums and Etags, and How Do MD5/SHA Compare to CRC for Integrity?
What Are Hot, Warm, Cold, and Archive Storage Tiers, and When Should I Use Each?
Design Patterns
What Is the Outbox Pattern, and How Does Change Data Capture (CDC) Work at a High Level?
What Is CQRS (Command Query Responsibility Segregation), and When Should I Consider It?
What Are the Differences Between a Circuit Breaker, Retry With Backoff, and Rate Limiting?
Reliability and Operations
What Are RPO and RTO, and How Do They Differ in Disaster Recovery Planning?
What Is the Difference Between Active‑Active and Active‑Passive Architectures?
What Is Graceful Degradation, and How Do Feature Flags Help Availability?
Time and IDs
What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose?
How Do Snowflake‑Style IDs Work (Timestamp, Worker, Sequence), and What Problems Do They Solve?
What Is the Difference Between Wall‑Clock Time and Monotonic Time, and Why Is Clock Skew Hard?
Final Words
Key Takeaways
What To Learn Next
What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose?

UUID, ULID, KSUID, and Snowflake ID are all schemes for generating globally unique identifiers.

In brief, UUIDs are 128-bit random identifiers, ULIDs and KSUIDs are time-encoded identifiers (128-bit and 160-bit respectively) that sort in creation order, and Snowflake IDs are 64-bit numeric identifiers combining a timestamp, machine ID, and sequence counter.

Each format trades off size, readability, and ordering guarantees to suit different distributed-system needs.

What is a UUID?

A UUID (“Universally Unique Identifier”, also known as GUID) is a 128-bit value (typically shown as a 36-character hex string) designed to be globally unique.

There are several versions, but the common one (version 4) is purely random (with 122 random bits and a few fixed version bits).

Because of its randomness, a UUIDv4 requires no coordination or central service: you can generate them independently on any machine and collisions are exceedingly unlikely.

  • Example: 550e8400-e29b-41d4-a716-446655440000 (a typical UUIDv4).

  • Properties: 128 bits (16 bytes), ~36 characters with hyphens; virtually collision-free; universally supported (almost every language/library has UUID support).

  • Drawbacks: Because UUIDs are random, they do not sort by creation time. In databases, inserting random UUIDs causes index fragmentation and performance overhead (new records land throughout the B-tree rather than sequentially). Also, 16-byte size is larger than 8-byte alternatives, doubling storage for large tables.

What is a ULID?

ULID stands for Universally Unique Lexicographically Sortable Identifier.

A ULID is a 128-bit ID (like a UUID) but structured as 48 bits of timestamp (milliseconds since Unix epoch) followed by 80 bits of randomness. It is typically encoded in a 26-character Base32 string (Crockford’s alphabet), e.g. 01ARZ3NDEKTSV4RRFFQ69G5FAV.

  • Key differences: Because the high-order bits are a timestamp, ULIDs sort naturally by creation time (lexicographically, since the string starts with the time). They are URL-safe, case-insensitive strings with no special characters. Inside the same millisecond, implementations typically increment the random part to enforce monotonic order.

  • Advantages: Time-ordered insertion improves database index performance (newer IDs come after older ones). ULIDs are more compact and human-friendly than UUID hex (26 chars vs 36). They convey approximate creation time (for debugging/analytics).

  • Trade-offs: ULID isn’t an official standard (though widely used) and needs a library to generate. Base32 strings are slightly longer than compact binary. If precise ordering beyond milliseconds is needed, collisions could occur (rare but possible) or additional logic is needed.

  • Example: A ULID looks like 01FZ2R0D6EH69M6B2YBP4N8Z57, where the first 48 bits encode the timestamp.

Differences Between UUID, ULID, KSUID, and Snowflake IDs
Differences Between UUID, ULID, KSUID, and Snowflake IDs

What is a KSUID?

KSUID stands for K-Sortable Unique Identifier. It is a 20-byte (160-bit) ID introduced by Segment.

A KSUID contains a 32-bit timestamp (seconds since a custom epoch in May 2014) followed by 128 bits of randomness.

The timestamp is big-endian so that the binary or text representation sorts by creation time. KSUIDs are encoded as 27-character Base62 strings (alphanumeric).

  • Structure: 32-bit timestamp + 128-bit random payload. In binary form it’s 20 bytes. Textually, the Base62 string (e.g. 0ujtsYcgvSTl8PAuAdqWYSMnLOv) is always 27 characters.

  • Advantages: KSUIDs are roughly time-ordered and contain more entropy than ULIDs. Because of the large random part (128 bits), collisions are virtually impossible even at enormous scale. They are also lexicographically sortable by timestamp without special handling. The Base62 string is compact and URL-safe.

  • Trade-offs: The format is custom (not a standardized UUID format), so built-in database UUID types won’t recognize it; you need a library. At 20 bytes, KSUIDs are longer than UUIDs or ULIDs. It may be overkill if you don’t need so much entropy or so long an ID.

  • Example: A KSUID might look like 0O8LYC0pTIQ3YcpwSQJPgUkB6aa, with the first few characters corresponding to a recent timestamp and the rest random.

What is a Snowflake ID?

Snowflake IDs were created by Twitter (now X) for generating unique 64-bit integers across distributed systems.

A standard Snowflake ID has 64 bits (with 63 bits used for positive range):

  • Bits layout: 1 sign bit (unused, always 0) + 41 bits timestamp (milliseconds since a custom epoch) + 10 bits machine/worker ID + 12 bits sequence number. For example, Twitter’s epoch is in 2010, giving ~69 years of millisecond-range timestamps.

  • Key properties: Newer Snowflake IDs are numerically larger (strictly time-ordered). They embed the creation time and machine origin, so you can extract the timestamp or shard info if needed. At each machine, up to 4096 IDs can be generated per millisecond (sequence resets each ms).

  • Advantages: Snowflakes are small (8 bytes) and fast to generate with simple bit shifts. They require no external coordination beyond assigning unique machine IDs. Because they are mostly time-based, database inserts are naturally ordered and index-friendly. They have built-in timestamp info for analytics, eliminating a separate “created_at” column.

  • Trade-offs: Snowflake IDs are not cryptographically random and require synchronized clocks. If clocks go backwards or two workers share an ID, you risk duplicates. You must manage a unique worker/machine ID for each generator. Also, 63 bits limits you to ~69 years and a fixed throughput per machine.

  • Example: A Snowflake ID might look like 1888944671579078978 (a 64-bit integer). Breaking it down shows a 41-bit timestamp, a 10-bit shard ID, and a 12-bit sequence.

Key Differences

  • Size & format: UUIDs and ULIDs are 128 bits (16 bytes). KSUIDs are 160 bits (20 bytes). Snowflake is only 64 bits (8 bytes). UUIDs are typically shown as 36-char hex strings; ULIDs as 26-char Base32; KSUIDs as 27-char Base62; Snowflakes are often unsigned 64-bit numbers (or decimal strings).

  • Ordering: UUIDv4 is random, so it offers no chronological order. ULIDs and KSUIDs both prefix a timestamp, so sorting by their string will sort by time. Snowflake IDs are also time-ordered by design. In practice, ULIDs/KSUIDs and Snowflakes yield new values that naturally append at the end of an index, reducing fragmentation.

  • Entropy & collision: UUIDv4 has ~122 bits of randomness; KSUID has 128 bits of random payload (more entropy than UUID); ULID has 80 random bits. All are astronomically unlikely to collide. Snowflake IDs rely on time/machine/sequence (no random bits), but collisions are avoided by the design of worker IDs and sequences.

  • Library/standard support: UUIDs are standardized (RFC 4122) and supported everywhere (databases often have a native UUID type). ULID is a newer format (no official RFC yet) and requires a library, though many languages have ULID implementations. KSUID is proprietary to Segment (with libraries available). Snowflake is an algorithm/pattern rather than a formal standard; many cloud services and libraries implement it (e.g. Twitter Snowflake, Discord, Instagram variants).

When to choose which

  • Use UUID when simplicity and compatibility matter. UUIDv4 needs no central coordination and is supported everywhere. It’s a good default if you just need a unique key (e.g. user IDs, API tokens) and don’t care about sorting. Its randomness even helps prevent ID-guessing in public APIs. Just remember it’s larger and can slow down highly write-heavy indexes.

  • Use ULID when you want sortable IDs without coordination. Because ULIDs encode the timestamp, new records sort chronologically by default. This improves database insert performance and lets you do range queries by creation time. ULIDs (26-char alphanumeric) are also shorter and more human-readable than UUID hex. They’re ideal for event logs, ordered streams, or any system where you want to preserve time order in the ID.

  • Use KSUID when you need the benefits of ULID but with extra entropy or a longer timeline. KSUIDs also sort by time, but use a 32-bit timestamp (versus 48-bit in ULID) and a 128-bit random part. The extra random bits make collisions even less plausible, and the custom epoch (2014 start) gives you >100 years of space. In practice, KSUID is great for high-scale event systems (Kafka, log streams, distributed databases) where sorted, globally unique IDs are needed.

  • Use Snowflake when you want compact numeric IDs with ordering. A 64-bit Snowflake ID is easier to store than 128-bit keys and natively sorts by time. This is popular for large-scale systems (Twitter, Discord, etc.) that need millions of unique IDs per second without a single bottleneck. Snowflake requires managing worker IDs and clock sync, so it fits environments where you can control instances (microservices, cloud VMs). It’s ideal if your database or downstream systems prefer integer keys or if you need embedded timestamp/shard info.

  • Special cases: In Microsoft/.NET ecosystems, “GUID” (their name for UUID) is common by default. If you need a URL-friendly short token, consider NanoID (not asked here) which is much shorter but uses randomness. But among the four: UUID for general-purpose uniqueness, ULID/KSUID for time-ordered IDs in logs/events, and Snowflake for 64-bit high-throughput ID generation.

Practical Scenarios

  • A web app creating user accounts might use UUIDs: they’re easy and ensure no clashes when merging data.

  • An event logging system could use ULIDs or KSUIDs so logs naturally sort and you can query by time without a separate timestamp column.

  • A distributed database sharding strategy could employ Snowflake IDs as primary keys to avoid cross-node coordination.

  • In an interview or design discussion, you might say: “We could use UUIDv4 if we just need unique keys; if we need sorted IDs for indexing we’d use ULID or KSUID; for a compact time-based ID, Snowflake is a classic choice”.

What Is Graceful Degradation, and How Do Feature Flags Help Availability?
How Do Snowflake‑Style IDs Work (Timestamp, Worker, Sequence), and What Problems Do They Solve?
Mark as Completed

On this page

What is a UUID?

What is a ULID?

What is a KSUID?

What is a Snowflake ID?

Key Differences

When to choose which

Practical Scenarios